#ifndef _io_lib_file_stream_h_
#define _io_lib_file_stream_h_

#include "win32/lean_windows.h"
#include "io/stream.h"

// Concrete Win32 file stream class.
struct File_Stream : Raw_Stream
{
protected:
	HANDLE m_file;

public:
	// Open a file for reading and writing. 'filename' is discarded after
	// file is opened.
	File_Stream(const char* filename);

	// Read at most 'count' elements into buf. Return number of actual
	// bytes read. Advance pos().
	virtual int64 read(char* buf, int count);

	// Write 'count' elements. Advance pos() if applicable.
	virtual void write(const char* buf, int64 count);

	// Seek to given position.
	// pre(0 <= pos && pos <= length());
	// post(pos() == pos);
	virtual void seek(int64 pos);

	// Position.
	// post(0 <= pos() && pos() <= length());
	virtual int64 pos();

	// Total length.
	// post(length() >= 0);
	virtual int64 length();

	// Set length of file.
	// post(length() == length);
	// post(0 <= pos && pos <= length());
	virtual void length(int64 length);

	// Close the file handle.
	virtual ~File_Stream();
};

#endif